import * as mongoose from 'mongoose';
import config from 'src/config';


function createLogConnectUrl(){
	var url=""
	if(config.logDB.username&&config.logDB.password){
		url=`mongodb://${config.logDB.username}:${config.logDB.password}@${config.logDB.host}:${config.logDB.port||27017}/${config.logDB.dbname}`
	}else{
		url=`mongodb://${config.logDB.host}:${config.logDB.port||27017}/${config.logDB.dbname}`
	}
	url+="?directConnection=true"
	return url
}
export const LogsDBProviders = {
	provide: 'LOG_DATABASE_CONNECTION',
	useFactory: async (): Promise<mongoose.Connection> =>{
		let conn=await mongoose.createConnection(createLogConnectUrl())
		return conn
	},
};
